W1: Intro to Computing

Welcome!

Please sign-up for an account at Posit Cloud and accept our classroom invitation here: https://posit.cloud/spaces/638111/join?access_code=rc5zywUOlT58wM2TE9sKcsbuoykuE1rGuWCOyrG7

Introductions

  • Who am I?
  • Who are you?

    • Name, pronouns, group you work in

    • What you want to get out of the class

    • Favorite spring activity

  • Our wonderful TAs!

Goals of the course

  • Fundamental concepts in programming languages: How do programs run, and how do we solve problems effectively using functions and data structures?
  • Data science fundamentals: How do you translate your scientific question to a data wrangling problem and answer it?

    Data science workflow

Content of the course

  1. Intro to Computing

  2. Data structures

  3. Data wrangling 1

  4. Data wrangling 2

  5. Data visualization

  6. Wrap-up, Pizza

Culture of the course

  • Challenge: We are learning a new language, but you already have a full-time job.
  • Teach not for mastery, but teach for empowerment to learn effectively.
  • Teach at learner’s pace.

Culture of the course

  • Challenge: We sometimes struggle with our data science in isolation, unaware that someone two doors down from us has worked on something similar.
  • We learn and work better with our peers.
  • We encourage discussion and questions, as others often have similar questions also.

Format of the course

  • Hybrid, and recordings will be available.
  • 1 hour exercises after each session are encouraged for practice.
  • Office Hours Mondays Noon-1pm.

Badge of completion

We offer a badge of completion when you finish the course!

What it is:

  • A display of what you accomplished in the course, shareable in your professional networks such as LinkedIn, similar to online education services such as Coursera.

What it isn’t:

  • Accreditation through an university or degree-granting program.

Requirements:

  • Complete badge-required sections of the exercises for 4 out of 5 assignments.

Ready?

What is a computer program?

  • A sequence of instructions to manipulate data for the computer to execute.
  • A series of translations: English <-> Programming Code for R Console <-> Machine Code

We will focus on English <-> Programming Code for R Interpreter in this class.

Setting up Posit Cloud and trying out your first analysis!

Classroom link here.

Open up “Week 1 Classwork” once you are in the classroom.

Break

Pre-course survey here: https://forms.gle/bakYJ218Xu5EdSRv6

Grammar Structure 1: Evaluation of Expressions

Consider the expression:

max(18, 21)
[1] 21
  • Expressions are built out of functions or operations.
  • Functions and operations take in data types as inputs, and return another data type as output.
  • If the function or operation input contains expressions, evaluate those expressions first.

Examples

18 + 21
[1] 39
max(18, 21)
[1] 21
max(18 + 21, 65)
[1] 65
18 * (21 + 65)
[1] 1548
nchar("ATCG")
[1] 4

Interpreting functions

Function machine from algebra class.
  • To use a function, we only need to know what the expected inputs and outputs are. The inner workings don’t matter yet.
  • A function can have different kinds of inputs and outputs - it doesn’t need to be numbers.

Data types

  • Numeric: 18, -21, 65, 1.25

  • Character: “ATCG”, “Whatever”, “948-293-0000”

  • Logical: TRUE, FALSE

Grammar Structure 2: Storing variables in the environment

To build up a computer program, we need to store our returned data type from our expression somewhere for downstream use.

age = 18 + 21

Evaluate the expression to the right of =.

Bind variable on the left of = to the resulting value.

Then the variable is stored in the environment.

Downstream

Look, now age can be reused downstream:

age - 2
[1] 37
age_double = age * 2
age_double
[1] 78

What’s the data type of a variable?

class(age_double)
[1] "numeric"

More practice

(sqrt(nchar("hello")) + 4) * (2 + 4)
[1] 37.41641
brothers_age = 45
grandmas_age = 90
age = max(brothers_age, grandmas_age)
secret = (nchar("hello") + age) * (2 + 4)
secret
[1] 570

Tips on writing your first code

Computer = powerful + stupid

  • Write incrementally: if function(a, b + c) isn’t working, examine a and b + c
  • The sequence of instructions you give matters! Refresh the page to clear the environment.
  • Ask for help!